package com.demo.springBoot2.result;

import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Author 750909637@qq.com
 * @PackageName demo
 * @Package com.edu.demo.demos.result
 * @Date 2024/3/6 19:20
 * @Version 1.0
 */
@Data // set和get方法
@AllArgsConstructor  // 全参构造函数
@NoArgsConstructor // 无参构造函数
public class Result<T> {
    @ApiModelProperty(value = "状态码,请参考状态码手册")
    private Integer code;
    @ApiModelProperty(value = "响应信息")
    private String msg;
    @ApiModelProperty(value = "响应结果")
    private T data;
    public Result code(Integer code) {
        this.code = code;
        return this;
    }
    public Result msg(String msg) {
        this.msg = msg;
        return this;
    }
    public Result(Integer code) {
        this.code = code;
    }

    public Result(Integer code, T data) {
        this.code = code;
        this.data = data;
    }

    /**
    * 请求成功
     * @return
    * */
    public static Result success() {
        return new Result(200);
    }

    public static Result success(Object data) {
        return new Result(200, data);
    }
    /**
     * 请求失败
     * @return
     * */
    public static Result error() {
        return new Result(500);
    }
    public static Result error(String msg) {
        return new Result(500,msg);
    }
    public static Result error(Integer code,String msg, Object data) {
        return new Result(500,msg,data);
    }
    public static Result message(String msg) {

        return new Result(400,msg);
    }
    public  Result data(T data) {
        this.data = data;
        return this;
    }

}
